package com.example.demo_test.Controller;

import com.example.demo_test.DTO.CreateGroupDto;
import com.example.demo_test.Entity.Group;
import com.example.demo_test.Entity.Result;
import com.example.demo_test.Service.GroupChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhanghong
 * @date 2021/6/8  0008 14:49
 */
@RestController
@RequestMapping("/groupChat")
public class GroupChatController {
    @Autowired
    private GroupChatService groupChatService;
    @GetMapping("/getGroup")
    public List<Group> getGroup(@Param( "userId" ) String userId){
        return groupChatService. getGroup(userId);
    }
    @PostMapping("/createGroup")
    public Result createGroup(@RequestBody CreateGroupDto createGroupDto){
        return groupChatService.createGroup(createGroupDto);
    }
    @PostMapping("/inviteFriends")
    public Result inviteFriends(@Param( "userIdList" ) String[] userIdList,@Param( "groupId" )int groupId,@Param( "currentUserId" )String currentUserId,@Param( "groupName" )String groupName){
        return groupChatService.inviteFriends(userIdList,groupId,currentUserId,groupName);
    }
    @GetMapping("exitGroupChat")
    public Result exitGroupChat(@Param( "userId" ) String userId,@Param( "groupId" )String groupId){
        return groupChatService.exitGroupChat(userId,groupId);
    }
    @GetMapping("deleteGroupChat")
    public Result deleteGroupChat(@Param( "groupId" )String groupId){
        return groupChatService.deleteGroupChat(groupId);
    }
}
